package models.sys;

import models.BaseModel;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;

import packaged.SessionManager;
import play.Play;
import play.db.jpa.JPABase;
import play.mvc.Scope;

/**
 * @author deekian
 */
@MappedSuperclass
public abstract class BaseSystemModel extends BaseModel {
    private static boolean trash = "true".equals(Play.configuration.getProperty("system.model.trash"));
    /**
     * 默认值为1(未锁定)
     */
    @Column(columnDefinition = "INT default 1")
    public Integer enabled;

    @Override
    public <T extends JPABase> T delete() {
        if (trash) {
            Table table = this.getClass().getAnnotation(Table.class);
            if (table != null) {
                new Trash(table.name(), this.toJSON(), AdminUser.findByInfo(SessionManager.getUserInfo())).save();
            }
        }
        return super.delete();
    }
}
